
import numpy as np

# 广播：numpy对不同形状的数组进行数值计算的方式
def fun1():
    a = np.array([1, 2, 3, 4])
    b = np.array([10, 20, 30, 40])
    c = a * b
    print(c)

def fun2():
    a = np.array([[0, 0, 0],
                  [10, 10, 10],
                  [20, 20, 20],
                  [30, 30, 30]])
    b = np.array([0, 1, 2])
    print(a + b)

def fun3():
    a = np.array([[0, 0, 0],
                  [10, 10, 10],
                  [20, 20, 20],
                  [30, 30, 30]])
    b = np.array([1, 2, 3])
    # 重复b的各个维度
    bb = np.tile(b, (4, 1))
    print(bb)
    print(a + bb)

if __name__ == '__main__':
    fun3()